Skip to content

Allow removal and adding for plugins in iconMenu#861

Open
oeninghe-dataport wants to merge 3 commits into
nextfrom
fix/668-iconMenu-plugin-removal
Open

Allow removal and adding for plugins in iconMenu#861
oeninghe-dataport wants to merge 3 commits into
nextfrom
fix/668-iconMenu-plugin-removal

Conversation

@oeninghe-dataport

Copy link
Copy Markdown
Collaborator

Summary

Plugins in iconMenu can be added and removed at runtime.

Note:
coreStore.removePlugin(...) is still not supported for plugins within iconMenu. I deem this correct. As iconMenu adds the plugin, it should also be responsible for removal of the plugin. Otherwise, we'd need to breach the separation of core and plugins.

Instructions for local reproduction and review

  • Open snowbox.
  • Add the layer "Anliegen (MML)"
  • Open filter plugin.
  • Filter out some "Anliegen".
  • Press the newly-introduced "Add/Remove filter plugin" button.

Relevant tickets, issues, et cetera

Fixes #668

@oeninghe-dataport oeninghe-dataport added this to the POLAR@3 milestone Jul 6, 2026
@oeninghe-dataport oeninghe-dataport self-assigned this Jul 6, 2026
@oeninghe-dataport oeninghe-dataport requested a review from a team July 6, 2026 08:38
@oeninghe-dataport oeninghe-dataport added the bug Something isn't working label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://Dataport.github.io/polar/pr-preview/pr-861/

Built to branch gh-pages at 2026-07-06 08:41 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@dopenguin dopenguin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/plugins/filter/store.ts
Comment on lines +119 to +125
watch(open, (open) => {
if (open) {
openInMoveHandle(open)
} else {
coreStore.setMoveHandle(null)
}
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the previously implemented version in favour of this side effect solution. Same goes for focusOpen.

What is the practical reason why this is needed or is simply personal preference?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Practical reason.

We had that logic already duplicated in NineRegionsButton and StandardMenuList, and I don't wanted to copy it a third time at https://github.com/Dataport/polar/pull/861/changes#diff-8793dc8dda9a07c08b84fcfa5edf13989ab72fde14867879719bfba5765c229aR59-R64

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be de-duplicated by abstracting the toggle functions of both components into an action.
I deem this favourable over the side-effect solution.

Comment on lines -67 to -84
// Otherwise, the component itself is made reactive
menus.value.map((menuGroup) =>
menuGroup.map((menuItem) =>
toMerged(menuItem, {
plugin: {
component: markRaw(menuItem.plugin.component as Component),
},
})
)
)
focusMenus.value.map((menuItem) =>
toMerged(menuItem, {
plugin: {
component: markRaw(menuItem.plugin.component as Component),
},
})
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important part - making the component non-reactive with markRaw - seems to be lost on the new implementation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines have no effect anymore. Or do I miss anything?

Comment on lines +47 to +69
watch(
flatMenuItems,
(newItems, oldItems) => {
const getDiffItems = (to, from) =>
to.filter(
(item) =>
!from.some((oldItem) => oldItem.plugin.id === item.plugin.id)
)
getDiffItems(newItems, oldItems).forEach((newItem) => {
coreStore.addPlugin(toMerged(newItem.plugin, { independent: false }))
})
getDiffItems(oldItems, newItems).forEach((oldItem) => {
if (open.value === oldItem.plugin.id) {
open.value = null
}
if (focusOpen.value === oldItem.plugin.id) {
focusOpen.value = null
}
coreStore.removePlugin(oldItem.plugin.id)
})
},
{ deep: true }
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that iconMenu should handle the removal itself so the separation of concerns is not broken.

However, I would've thought adding its own removePlugin action that handles that procedure would be the way to go here. Note that, even though they are currently described otherwise in the export, neither menu nor focusMenus are considered stable API. I've made a note for myself to go over all plugins to adjust the exports to the requirements and mark most as @alpha.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first approach was to implement a addPlugin and removePlugin action. However, they get quite complicated, as you have to check which index and subindex to consider, remove an empty array if it is empty; and insertion similar.

If you prefer to have these actions, I can add them. I'd stick to this watcher to keep the more flexible option of direct editing, but we could e.g. mark only the actions as stable to keep menus as unstable API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer these actions, yeah.

@oeninghe-dataport

Copy link
Copy Markdown
Collaborator Author

🏓 @dopenguin

@dopenguin

Copy link
Copy Markdown
Member

🏓 @dopenguin

🏓 @oeninghe-dataport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugins added by IconMenu can not be removed with "removePlugin"

2 participants